package com.itheima.test;

import java.util.Random;
import java.util.Scanner;

public class Test3 {
    public static void main(String[] args) {
        //键盘输入任意字符串，打乱里面的顺序

        //1.键盘录入字符串
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个字符串：");
        String str1 = sc.next();

        //2.把字符串变成字符数组
        char[] arr = str1.toCharArray();

        //3.遍历数组，用随机数打乱顺序
        Random r = new Random();
        for (int i = 0; i < arr.length; i++) {
            //随机生成索引
            int index = r.nextInt(arr.length);
            //交换数据
            char tmp = arr[i];
            arr[i] = arr[index];
            arr[index] = tmp;
        }

        //4.循环结束后，字符数组已经打乱，再转换为字符串
        String result = new String(arr);

        //5.输出打印打乱顺序的字符串
        System.out.println(result);
    }
}
